package com.deneme.ozveri.adapters;

import java.util.ArrayList;

import com.deneme.ozveri.objects.MenuItem;
import com.deneme.ozveri.objects.MenuOrderItem;
import com.deneme.ozverimenu.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MenuItemListAdapter extends BaseAdapter {
	
	private ArrayList<MenuItem> menuItems;
	private Context ctxt;
	
	public MenuItemListAdapter(ArrayList<MenuItem> items, Context context) {
		
		this.menuItems = items;
		this.ctxt = context;
		
	}

	@Override
	public int getCount() {
		return menuItems==null?0:menuItems.size();
	}

	@Override
	public Object getItem(int position) {

		return menuItems==null?0:menuItems.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		LinearLayout itemLayout;
		LayoutInflater inflater = (LayoutInflater) ctxt
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		if (menuItems == null || menuItems.size() == 0) {
			return null;
		}

		MenuItem currItem = menuItems.get(position);

		itemLayout = (LinearLayout) inflater.inflate(
				R.layout.menuchoice, parent, false);

		TextView name = (TextView) itemLayout
				.findViewById(R.id.menuchoice_txt);
		name.setText(currItem.getMenuName());

		ImageView smallImage =(ImageView) itemLayout.findViewById(R.id.menuchoice_image);
		smallImage.setImageResource(R.drawable.ic_launcher);

		itemLayout.setBackgroundColor((position % 2) == 1 ? ctxt
				.getApplicationContext().getResources()
				.getColor(R.color.rowcolor0) : ctxt.getApplicationContext()
				.getResources().getColor(R.color.rowcolor1));

		return itemLayout;

	}

}
